﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace HooIzDat.Web.Helpers
{
    public static class IEnumerableExtensions
    {
        public static IEnumerable<T> TakeRandom<T>(this IEnumerable<T> items, int count)
        {
            var source = new List<T>(items);

            if (source.Count < count)
                throw new ArgumentException("There are not enough items to satisfy the number requested.");

            var result = new List<T>();
            var rdm = new Random();
            for (var i = 0; i < count; i++)
            {
                result.Add(source.Except(result).Skip(rdm.Next(source.Count - result.Count)).First());
            }
            return result;
        }
    }
}